<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Attribute Modification
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot098.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot093.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot100.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc223">16.6</A>&nbsp;&nbsp;Attribute Modification</H2>
Often an extension needs to modify the data stored in the
attribute to reflect changes in the computation.
The usual Prolog way to do this is by reserving
one argument in the attribute structure for this next value.
before accessing the most recent attribute value this chain
of values has to be dereferenced until a value is found whose
link is still free.
A perfect compiler should be able to detect that the older
attribute values are no longer accessed and it would compile
these modifications using destructive assignment.
Current compilers are unfortunately not able to perform
this optimization (some systems can reduce these chains
during garbage collection, but until this occurs,
the list has to be dereferenced for each access and update).
To avoid performance loss for both attribute updating and
access, ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> provides a predicate for explicit
attribute update: 
<B>setarg(I, Term, NewArg)</B> will update the <B>I</B>'th
argument of <B>Term</B> to be <B>NewArg</B>.
Its previous value will be restored on backtracking.
<BR>
<BR>
Libraries which define user-programmable extensions
like e.g. <B>fd.pl</B> usually define predicates that
modify the attribute or a part of it, so that an explicit
use of the <A HREF="../bips/kernel/termmanip/setarg-3.html"><B>setarg/3</B></A><A NAME="@default906"></A> predicate is not necessary.<BR>
<BR>
<HR>
<A HREF="umsroot098.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot093.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot100.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
